From abedcdb6c94f60a20e11a194cdcc428610d65dad Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 20 Nov 2015 21:41:05 +0530 Subject: [PATCH] Improve diagnostics for multiple native links for the same package --- src/cargo/ops/cargo_rustc/links.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/links.rs b/src/cargo/ops/cargo_rustc/links.rs index 8f152d76c..2021ffd75 100644 --- a/src/cargo/ops/cargo_rustc/links.rs +++ b/src/cargo/ops/cargo_rustc/links.rs @@ -1,12 +1,12 @@ use std::collections::HashMap; -use core::PackageSet; +use core::{PackageId, PackageSet}; use util::{CargoResult, human}; // Validate that there are no duplicated native libraries among packages and // that all packages with `links` also have a build script. pub fn validate(deps: &PackageSet) -> CargoResult<()> { - let mut map = HashMap::new(); + let mut map: HashMap<_, &PackageId> = HashMap::new(); for dep in deps.iter() { let lib = match dep.manifest().links() { @@ -15,11 +15,25 @@ pub fn validate(deps: &PackageSet) -> CargoResult<()> { }; match map.get(&lib) { Some(previous) => { - return Err(human(format!("native library `{}` is being linked \ - to by more than one package, and \ - can only be linked to by one \ - package\n\n {}\n {}", - lib, previous, dep.package_id()))) + let depid = dep.package_id(); + if previous.name() == depid.name() + && previous.source_id() == depid.source_id() { + return Err(human(format!("native library `{}` is being \ + linked to by more than one \ + version of the same package, but \ + it can only be linked \ + once; try updating \ + or pinning your dependencies to \ + ensure that this package only \ + shows up once\n\n {}\n {}", + lib, previous, dep.package_id()))) + } else { + return Err(human(format!("native library `{}` is being \ + linked to by more than one \ + package, and can only be linked \ + to by one package\n\n {}\n {}", + lib, previous, dep.package_id()))) + } } None => {} } -- 2.30.2